#pragma once 

void conf2clust(complex C[], complex Cclust[],int Nconf, int Nclust, int iconf_ex){

/*	complex sum;
	int Nratio=Nconf/Nclust;
	complex Caux[Nclust+1];
	for (int iclust=0; iclust<Nclust; iclust++)
	{
		Caux[iclust]=0.;
		for (int iratio=0; iratio<Nratio; iratio++)
		{
			int isum=Nratio*iclust+iratio;
			Caux[iclust]=Caux[iclust]+C[isum]/Nratio;
		}

	}
	sum=0;
	for (int iclust=0; iclust<Nclust; iclust++)
	{
		sum=sum+Caux[iclust]/Nclust;
	}
	
	Cclust[Nclust]=sum;
	for (int iclust=0; iclust<Nclust; iclust++)
	{
		Cclust[iclust]=(sum*Nclust-Caux[iclust])/(Nclust-1);
	}
*/
      int iconf_n  = (Nclust-1)*iconf_ex;
        for (int clust=0;clust<Nclust+1;clust++) Cclust[clust]=0;
        int iconfmin,iconfmax;
        for (int clust=0;clust<Nclust;clust++){
                                iconfmin=clust*iconf_ex;
                                iconfmax=(clust+1)*iconf_ex;
                                for (int iconf=0;iconf<iconfmin;iconf++){
                                        Cclust[clust]=Cclust[clust]+C[iconf];
                                }
                                for (int iconf=iconfmax;iconf<Nconf;iconf++){
                                        Cclust[clust]=Cclust[clust]+C[iconf];
                                }
                                Cclust[clust]=Cclust[clust]/iconf_n;

        }
        for (int iconf=0; iconf<Nconf; iconf++) Cclust[Nclust]=Cclust[Nclust]+C[iconf];
        Cclust[Nclust]=Cclust[Nclust]/Nconf;


}


complex error_jack(complex P[],int Nclust){
        double ejack_real=0., ejack_imag=0.;
	complex ejack;
        for (int clust=0; clust<Nclust; clust++){
                ejack_real=ejack_real+pow(creal(P[clust])-creal(P[Nclust]),2);
		ejack_imag=ejack_imag+pow(cimag(P[clust])-cimag(P[Nclust]),2);
        }
        ejack_real=sqrt(((Nclust-1.)/Nclust)*ejack_real);
	ejack_imag=sqrt(((Nclust-1.)/Nclust)*ejack_imag);
	ejack=ejack_real+I*ejack_imag;
        return ejack;
}
double error_jack_real(double P[],int Nclust){
        double ejack_real=0.;
        for (int clust=0; clust<Nclust; clust++){
                ejack_real=ejack_real+pow(P[clust]-P[Nclust],2);
        }
        ejack_real=sqrt(((Nclust-1.)/Nclust)*ejack_real);
        return ejack_real;
}

